home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1994
/
MacHack 1994.toast
/
MacHack™94
/
Talks & Papers
/
Michael D. Crawford↵
/
Word Services SDK 1.0.5
/
Writeswell Jr. Source
/
TableCheck.c
< prev
next >
Wrap
Text File
|
1993-03-17
|
5KB
|
151 lines
/* DoChecking.c
* Functions that actually do the calls to the Word Services servers.
* ©1992 Working Software, Inc.
* This source code is copyrighted. Permission is granted to use the Word Services
* portion of the Writeswell Jr. source code in your own programs, but you
* may not distribute the Writeswell Jr. word-processor code as a
* commercial product. If you modify the code, please do not call it
* Writeswell Jr. (or Writeswell.) This will ensure that people understand the
* program and don’t have to deal with a number of different versions with
* who-knows-what going on in the code.
*
* Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
* 24 Sep 92 Mike Crawford
*/
#include <AppleEvents.h>
#include <AEObjects.h>
#include <AEPackObject.h>
#include <AERegistry.h>
#include "TBConstants.h"
#include "TBGlobals.h"
#include "WordServices.h"
#include "AppEvents.h"
#include "ObWind.h"
#include "Gripe.h"
#include "Prefs.h"
#include "TableCheck.h"
OSErr DoBatchTableCheck( AEAddressDesc *spellerAddrPtr )
{
OSErr err;
AEDesc tableSpec;
AEDesc textDescriptor;
AEDesc textSpecifier;
AppleEvent btchEvent;
AppleEvent replyEvent;
WWJrPrefsHdl prefHdl;
AEDescList textSpecList; /* 1.0d7 */
long index; /* 1.0d7 */
/* In this case we don't send the object specifiers for the text explicitly.
* Instead, we send a single object specifier for a table of object specifiers.
* The speller can then ask for them one at a time.
*
* In our particular case, the table is just the document window. The elements of
* the table are the elements of typeObjectSpecifier within the window.
*
* There's just one element in our particular case.
*
* I'm not real sure about what the best way to do this is. The way the protocol
* works, the table can be anything, within any container. The table itself can
* have any type. It just needs to have elements that are object specifiers.
*/
/* We make an object specifier that refers to _our_own_ window
*/
err = BuildWindowSpecifier( &tableSpec, 1 );
if ( err ){
Gripe( "\pBuildWindowDescriptor failed" );
return err;
}
/* Create the event to send to the speller */
err = AECreateAppleEvent( kWordServicesClass,
kWSBatchCheckMe,
spellerAddrPtr,
kAutoGenerateReturnID,
kAnyTransactionID,
&btchEvent );
if ( err ){
Gripe( "\pcreate btch event failed" );
return err;
}
err = AEDisposeDesc( spellerAddrPtr );
if ( err ){
Gripe( "\pAEDisposeDesc failed" );
return err;
}
/* Insert the table specifier as the direct object of the batch event */
err = AEPutParamDesc( &btchEvent,
keyDirectObject,
&tableSpec );
if ( err ){
Gripe( "\pAEPutParamDesc failed to put direct object on batch event" );
return err;
}
err = AEDisposeDesc( &tableSpec ); /* 1.0d12 was textSpecifier... bad bug */
if ( err ){
Gripe( "\pAEDisposeDesc failed" );
return err;
}
/* Send the event. We await the reply, so that if there is a failure of some
* sort in the initial connection, we can alert the user right away. The timeout
* value to use here should be as long as one would care to have a user wait for
* the completion of a menu command. Since we expect that the speller is on a local
* machine in this case, and should be able to respond immediately, we just give
* a few seconds for the timeout.
*
* We should assign an idle proc to spin the cursor. Even better would be a progress
* dialog that says "Contacting speller" or some such, with an animated display that
* shows the time elapsed relative to the total timeout, so the user will know how
* long she may have to wait
*/
#define kFewSeconds 300
err = AESend( &btchEvent,
&replyEvent,
kAEWaitReply + kAECanInteract + kAECanSwitchLayer,
kAENormalPriority,
kFewSeconds,
(IdleProcPtr)NULL,
(EventFilterProcPtr)NULL );
if ( err ){
Gripe( "\psend btch event failed" );
return err;
}
err = AEDisposeDesc( &btchEvent );
if ( err ){
Gripe( "\pAEDisposeDesc failed" );
return err;
}
/* MDC 1.1.1 */
err = AEDisposeDesc( &replyEvent );
if ( err ){
Gripe( "\pAEDisposeDesc failed" );
return err;
}
/* Now the event has been sent. There is nothing more that we have to actually do
* on our own initiative to accomplish the spelling; we just sit back and respond
* to events. In particular, we don't remember that spelling is taking place - once
* the spelling is done, we will just start seeing events from the user (mouse and
* key clicks and so on
*/
return noErr;
}